{extend name="user_base" /} {block name="seo"}
<title>在线投稿 - {$site_config['seo_title']}</title>
<meta name="keywords" content="{$site_config['seo_keyword']}">
<meta name="description" content="{$site_config['seo_description']}">
{/block}
{block name="css"}
<link rel="stylesheet" href="__PUBLIC__/plugins/wangEditor/css/wangEditor.min.css">
<style>
    .wangEditor-menu-container .menu-item a {
        padding: 12px 0;
    }

    .wangEditor-menu-container .menu-item {
        height: 37px;
        width: 37px;
    }

    .wangEditor-menu-container .menu-group {
        padding: 0;
    }

    .wangEditor-container {
        border: 1px solid #e6e6e6;
    }
</style>
{/block}
{block name="main"}
<div class="title">
    在线投稿
    <a href="/about/tgrule.html" target="_blank">必看的投稿规则</a>
</div>
<form class="layui-form atuikeFormSkin1" id="list_form">
    <div class="layui-form-item">
        <label class="layui-form-label">投稿标题<font color="#FF0000"> *</font></label>
        <div class="layui-input-block">
            <input type="text"  name="title" placeholder="请填写标题" lay-verify="required"  lay-verify="title"  autocomplete="off"  class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">投稿内容<font color="#FF0000"> *</font></label>
        <div class="layui-input-block">
            <!--style给定宽度可以影响编辑器的最终宽度-->
            <textarea id="textarea" name="content" required="" lay-verify="required" placeholder="详细描述" class="layui-textarea fly-editor" style="height: 460px;"></textarea>
        </div>
    </div>
    <div class="inline-form layui-clear">
        <div class="layui-form-item">
            <label class="layui-form-label">投稿专区</label>
            <div class="layui-input-block">
                <select name="type_id"  lay-verify="required" title="选择分类">
                    <option value="">请选择分类</option>
                    {volist name="category" id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="width: 230px;">
            <label  class="layui-form-label">投稿封面 <i class="layui-icon layui-icon-tips" id="notice1"></i></label>
            <div class="layui-input-block">
                <div class="coverBox" hidden >
                    <img src="__HOME__/images/default.png" alt="">
                </div>
                <button  type="button" class="layui-btn layui-btn-primary uploadImg">
                    <i class="layui-icon layui-icon-picture-fine"></i> 上传
                </button>
                <input type="hidden" name="cover_img">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类　　型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="text"    title="纯文章" lay-filter="typeradio" checked>
            <input type="radio" name="type" value="file"    title="有附件" lay-filter="typeradio">
        </div>
    </div>
    <div class="layui-form-item zips" hidden>
        <label class="layui-form-label">附件<font color="#FF0000"> *</font></label>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-primary zipupload" type="button"  >
                <i  class="layui-icon layui-icon-upload-drag"></i> 上传附件
            </button>
        </div>
        <div class="layui-form-mid layui-word-aux beizupload">为减轻服务器压力，仅支持Zip/Rar/Mp4/Apk格式，大于{$site_config.upsize}M的附件请先上传到网盘，然后
            将下载地址贴到下方输入框中
        </div>
    </div>
    <div class="layui-form-item zips" hidden>
    <label class="layui-form-label"></label>
    <div class="layui-input-block">
        <input type="text" id="down_link1" name="down_link1" placeholder="可以直接写附件下载路径（或网盘下载地址）"   autocomplete="off"  class="layui-input"/>
    </div>
    </div>
    <!--div class="layui-form-item"><div class="layui-input-block"><font color="#ef0048">近期115资源网正在备案，目前服务器是国外线路，带有附件投稿的请先将资源上传到网盘再投稿</font></div></div-->


    <div class="layui-form-item jdt" hidden>
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <div class="layui-progress">
                <div class="layui-progress-bar" lay-percent="0%"></div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">投稿奖励</label>
        <div class="layui-input-block">
            <input type="checkbox"    name="is_need" placeholder="" lay-skin="switch" lay-filter="payopen">
        </div>
    </div>
    <div class="inline-form layui-clear pays" hidden>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="alipay_name" class="layui-input" placeholder="真实姓名"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付宝账号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="alipay_account" placeholder="支付宝账户">
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn atuikeBtnSkin1" lay-submit lay-filter="submitAll"  >立即投稿</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/plugins/wangEditor/js/wangEditor.js"></script>

<script type="text/javascript">
    var editor = new wangEditor('textarea');
    $.getJSON("{:url('index/index/getemotion')}", function(data) {
        editor.config.uploadImgUrl = '{:url("index/upload/wangeditor_upimage")}';
        editor.config.uploadImgFileName = 'FileName';
        var emotiondata;
        emotiondata = data;
        emotiondata = JSON.parse(emotiondata);
        editor.config.emotions = emotiondata;
        editor.config.pasteText = false;
        editor.create();
    });

    var _name = 'USER_TG_FORM_DATA_CACHE';
    var btnText = $(".atuikeBtnSkin1").html();
    layui.use(['form', 'layer', 'upload', 'element'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
        var element = layui.element;
        form.verify({
            title:function (val,item) {
                if (val.length<2){
                    return "标题过于简短的教程不会被收录";
                }
            }
        });

        $("#notice1").mouseover(function() {
            layer.tips('如文章中有图片，可以不必传。系统会默认读取内容中第一张的图片为封面图', this, {
                tips: [1, "#000"],'time':3000
            });
        });
        //监听提交
        form.on('submit(submitAll)', function (data) {

            if($(".atuikeBtnSkin1").html()!=btnText){
                return false;
            }

            // var content = editor.getContent();
            var auto_pass = $("input[name=auto_pass]");
            // if (( data.field.type==='text' && editor.getContentTxt().length<10 )){
            //     layer.msg('文章过于简短,',{icon:5});
            //     return false;
            // }
            if (data.field.auto_pass &&auto_pass.data('exempt')<1){
                layer.msg('免审次数不足,请使用普通投稿方式!',{icon:5});
                return false;
            }
            // data.field.content= content;
            $(".atuikeBtnSkin1").html('<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop" style="color:#FFF;font-size:24px;"></i>');
            request({
                data:data.field ,
                success:function (result) {
                    var open_data ={
                        type: 0,
                        shadeClose: true,
                        skin: 'atuikeLayerSkin1',
                        content: result.msg
                    };

                    if(result.code===1){
                        auto_pass.data('exempt',result.exempt_num);
                        $("#exempt").text(result.exempt_num);
                        result.code===1&&( open_data.btn=['我知道了','取消']);
                        open_data.yes = function(){
                            location.reload();
                        };
                        form_reset(data);
                    }else{

                    }
                    layer.open(open_data);
                    $(".atuikeBtnSkin1").html(btnText);
                }
            });
            return false
        });

        //奖励开关
        form.on('switch(payopen)', function (data) {
            if (data.elem.checked) {
                $(".pays").slideDown();
            } else {
                $(".pays").slideUp(100);
            }
        });

        //纯文章和附件
        form.on('radio(typeradio)', function (data) {
            if (data.value === "file") {
                $(".zips").slideDown();
            } else {
                $(".zips").slideUp(100);
            }
        });

        //监听上传封面
        var uploadImg = $(".uploadImg");
        var uploadInst = upload.render({
            elem: uploadImg,
            auto: false,
            accept:'image',
            //acceptMime:'image/*',
            choose: function (obj) {
                uploadImg.html('<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>');
                obj.preview(function(index, file, result){
                    $("input[name=cover_img]").val(encodeURIComponent(result));
                });
                setTimeout(function () {
                    uploadImg.css({'border-color':'#00ca5f','color':'#00ca5f'}).html("封面已选择");
                }, 1000);
            }
        });

        uploadImg.hover(function () {
            var box = $("div.coverBox");
            if (uploadImg.siblings("input[name=cover_img]").val().length>10){
                box.fadeIn(200);   box.find("img")[0].src=  decodeURIComponent(uploadImg.siblings("input[name=cover_img]").val());
            }
        },function () {
            $("div.coverBox").fadeOut(100)
        });

        //监听上传附件

        var pro = $(".jdt .layui-progress-bar");
        var fz = parseInt("200")*1024;
        var upload_element =  $(".zipupload");
        var softloadInst = upload.render({
            elem: upload_element,
            url: config.api.upload,
            auto: true,
            field:'file_name',
            size:fz,
            accept: 'file',
            acceptMime:'application/zip,application/rar,video/mp4,application/vnd.android.package-archive',
            exts: 'zip|rar|mp4|apk',
            progress: function (value) {	 //上传进度回调 value进度值
                var bfb = value + "%";
                pro.width(bfb );  upload_element.css('color','#00ca5f').html(bfb);
                if ( value >= 100) {
                    $(".jdt").fadeOut(500);
                }
            },
            choose: function () {
                $(".zipupload").html("上传中..");
                $(".jdt").slideDown(300);
            },
            done: function (result) {
                layer.msg(result.msg,{icon:result.code});
                if(result.code===1){
                    $('#down_link1').val(result.data.src);
                    upload_element.css({'border-color':'#00ca5f','color':'#00ca5f'}).html("<i class='layui-icon layui-icon-ok-circle'></i>上传成功");
                }else{
                    upload_element.css({'border-color':'#e73f49','color':'#e73f49'}).html("<i class='layui-icon layui-icon-face-surprised'></i>上传失败");
                }
                setTimeout(function () {
                    pro.width(0);
                },100)
            }
        });

        function form_reset(data) {

            var thisForm = $(data.elem).parents(".layui-form");
            thisForm.find(".layui-form-item").each(function (i,e) {
                $(e).find("input[type=text],input[type=hidden]").val("");
                $(e).find(".layui-form-onswitch").trigger("click");
                $(e).find(".uploadImg").css({'color':'#888','border-color':'#888'}).html('<i class="layui-icon layui-icon-picture-fine"></i>上传');
                $(e).find(".layui-form-radio").eq(0).trigger("click");
                $(e).find('.zipupload').css({'color':'#888','border-color':'#888'}).html('<i class="layui-icon layui-icon-upload-drag"></i>上传附件');
            });
            $("#myEditor").html("");
            layui.data(_name,null);
            form.render();
        }

    });


    /**
     * 设置缓存
     * */
    // setInterval(function () {
    //     var formData = $("#list_form").field();
    //     var cacheData = {};
    //     if (formData.title && editor.hasContents()){
    //         cacheData.title = formData.title;
    //         cacheData.content= editor.getContent();
    //         layui.data(_name, {key:_name, value:cacheData});
    //     }
    // },3000);

    /**
     * 恢复缓存
     */
    var cacheData = layui.data(_name)[_name];
    if (cacheData){
        $(".bj-content").append('<div class="contentTask">检测到您之前可能有编辑的文案，您可以选择<a class="hfContent" onclick="javaScript:restoreFormData();">恢复</a></div>');
    }
    function restoreFormData() {
        cacheData = layui.data(_name)[_name];
        $("#list_form").find("input[name=title]").val(cacheData.title);
        $("#myEditor").html(cacheData.content);
        $(".contentTask").remove();
    }
</script>
{/block}